package br.unb.ida.midialab.pedparq;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class TelaInstrucoes extends Activity{
	private static final String TAG = "instrucoes";
    private SharedPreferences mSettings;
    private PedometerSettings mPedometerSettings;

	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.instrucoes);
		
		mSettings = PreferenceManager.getDefaultSharedPreferences(this);
        mPedometerSettings = new PedometerSettings(mSettings);
        
        EditText editPeso = (EditText) findViewById(R.id.editPeso);
        EditText editTamPassos = (EditText) findViewById(R.id.editTamPasso);
        
        editPeso.setText(String.valueOf(mPedometerSettings.getBodyWeight()));
        editTamPassos.setText(String.valueOf(mPedometerSettings.getStepLength()));
        
	}
	
	public void configEntradas(View view){
		EditText editPeso = (EditText) findViewById(R.id.editPeso);
        EditText editTamPassos = (EditText) findViewById(R.id.editTamPasso);
        
		SharedPreferences.Editor editor = mSettings.edit();
		try {
			float peso = Float.parseFloat(editPeso.getText().toString());
			float tamPassos = Float.parseFloat(editTamPassos.getText().toString());
			
			if(peso > 10 && tamPassos > 0){
				editor.putString("body_weight", editPeso.getText().toString());
				editor.putString("step_length", editTamPassos.getText().toString());
				editor.putBoolean("isConfig", true);
				editor.commit();
				
				//chama a intent das opcoes
		    	Intent iOpcoes = new Intent(this, TelaOpcoes.class);
		    	startActivity(iOpcoes);
			}else{
				Toast.makeText(this, "peso ou tamanho do passo incorreto", Toast.LENGTH_LONG);
			}
		} catch (NumberFormatException e) {
			Toast.makeText(this, "peso ou tamanho do passo incorreto", Toast.LENGTH_LONG);
		}
	}
	
	
	
}
